<?php echo \think\facade\View::fetch("public/header"); ?>

    <div id="right">
        <div id="content">
            <div id="breadcrumb">
                <a href="/admin/index/index">首页</a> &gt;
                <a href="/admin/comment/index/">评论管理</a> &gt;评论列表
            </div>

            <div id="choose_div">
                筛选：
                <select id="select" >
                    <option  value="1" <?php if($status == 1){echo 'selected="selected"';}?>>正常</option>
                    <option value="2" <?php if($status == 2){echo 'selected="selected"';}?>>回收站</option>
                </select>
                <button id="all" class="btn">搜索</button>
            </div>

            <table class="list">
                <tbody>
                <tr>
                    <th></th>
                    <th>评论ID</th>
                    <th>评论内容</th>
                    <th>昵称</th>
                    <th>邮箱</th>
                    <th>文章id</th>
                    <th>状态</th>
                    <th>增加时间</th>
                    <th>更新时间</th>
                    <th>操作</th>
                </tr>
                <?php foreach ($commentList as $item): ?>
                    <tr>
                        <td><input type="checkbox" class="task-checkbox" name="TaskId[]" value=""></td>
                        <td><?php echo $item['comment_id']; ?></td>
                        <td><?php echo $item['comment_content']; ?></td>
                        <td><?php echo $item['nickname']; ?></td>
                        <td><?php echo $item['email']; ?></td>
                        <td><?php echo $item['article_id']; ?></td>
                        <td><?php echo $item['status']; ?></td>
                        <td><?php echo date("Y-m-d H:i:s", $item['add_time']); ?></td>
                        <td><?php echo date("Y-m-d H:i:s", $item['update_time']); ?></td>
                        <td>
                            <?php if($item['status'] == 1):?>
                                <a class="update_ing" href="/admin/comment/garbage/comment_id/<?php echo $item['comment_id']; ?>/">移入回收站</a>
                            <?php elseif($item['status'] == 2):?>
                                <a class="update_ing" href="/admin/comment/resume/comment_id/<?php echo $item['comment_id']; ?>/">恢复</a>
                                <a class="update_ing" href="/admin/comment/delete/comment_id/<?php echo $item['comment_id']; ?>/">彻底删除</a>
                            <?php endif;?>
                        </td>
                    </tr>
                <?php endforeach; ?>
                </tbody>
            </table>
        </div>
    </div>

<?php echo \think\facade\View::fetch("public/footer"); ?>
<script>

    //筛选按钮
    $('.btn').click(function () {
        let status = $('#select').val();
        let url = "/admin/comment/index/status/"+status+"";
        location.href = url;
    });

    //页面弹框
    $(".update_ing").click(function () {
        //获取页面a标签的href
        let href = $(this).attr('href');

        //获取本页面的标签
        let _this = this;

        $.ajax({
            url:href,
            type:"GET",
            success: function (result) {
                if(result.status == 1){
                    alert('移入回收站成功');
                    $(_this).parents('tr').remove();
                }else if(result.status == 2){
                    alert('恢复成功');
                    $(_this).parents('tr').remove();
                }else if(result.status == 3){
                    alert('彻底删除');
                    $(_this).parents('tr').remove();
                }else {
                    alert(result.message);
                }
            }
        });
        return false;
    });
</script>
